﻿using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Domain.Shop;
using MaxStoreShop.Logic.Services.Shop;
using MaxStoreShop.Logic.ServicesContracts.Shop;
using MaxStoreShop.Logic.Tests.FakeRepositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MaxStoreShop.Logic.Tests
{
    [TestClass]
    public class DebtorRuleServiceTests
    {
        [TestMethod]
        public void DeleteRuleShouldNormal()
        {
            CreateInstance().DeleteRule(new DebtorRule {Id = 1});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void DeleteRuleShouldThrowErpRuntimeExceptionIfRuleIsNull()
        {
            CreateInstance().DeleteRule(null);
        }

        [TestMethod]
        public void SaveRuleShouldNormal()
        {
            CreateInstance()
                .SaveRule(new DebtorRule {Character = new Character(), IsDebtDisabled = false, MaxDebtSize = 10});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveRuleShouldThrowErpRuntimeExceptionIfRuleIsNull()
        {
            CreateInstance().SaveRule(null);
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveRuleShouldThrowErpRuntimeExceptionIfCharacterIsNull()
        {
            CreateInstance().SaveRule(new DebtorRule {IsDebtDisabled = false, MaxDebtSize = 10});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveRuleShouldThrowErpRuntimeExceptionIfMaxDebtSizeIsNegative()
        {
            CreateInstance()
                .SaveRule(new DebtorRule {Character = new Character(), IsDebtDisabled = false, MaxDebtSize = -1});
        }

        [TestMethod]
        public void GetCharacterDebtRuleShouldNormal()
        {
            CreateInstance().GetCharacterDebtRule(new Character());
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void GetCharacterDebtRuleShouldThrowErpRuntimeExceptionIfCharacterIsNull()
        {
            CreateInstance().GetCharacterDebtRule(null);
        }

        static IDebtorRuleService CreateInstance()
        {
            return new DebtorRuleService(new DebtorRuleRepositoryFake());
        }
    }
}
